package com.yf.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yf.domain.security.Department;
import com.yf.model.query.DeptQueryCriteria;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

/**
 * @author chentianwei
 * @date 2023/6/25 11:04
 * @description 部门Dao
 */
@Mapper
public interface DepartmentMapper extends BaseMapper<Department> {

    List<Department> findAll(@Param("criteria") DeptQueryCriteria criteria);

    List<Department> findByPid(@Param("pid") Long pid);

    List<Department> findByPidIsNull();

    Set<Department> findByRoleId(@Param("roleId") Long roleId);

    @Select("select count(*) from sys_dept where pid = #{pid}")
    int countByPid(@Param("pid") Long pid);

    @Select("update sys_dept set sub_count = #{count} where dept_id = #{id}")
    void updateSubCntById(@Param("count") Integer count, @Param("id") Long id);

    List<Department> findByPidIsNullOrderByMenuSort();

    List<Department> findByPidOrderByMenuSort(@Param("pid") Long pid);
}
